// ================================================
// Builder.Alyr.Net 智能体生成文件 [Builder.Alyr.Net] [2025-07-28]
// (c) 2020-2025 ALYR.NET
// ================================================

const AutoFixHelper = require('./auto-fix-helper.js');
const path = require('path');
const chalk = require('chalk');

async function main() {
  const args = process.argv.slice(2);
  
  if (args.length === 0) {
    console.log(chalk.cyan('🔧 Builder.Alyr.Net 文件修复工具'));
    console.log(chalk.white('用法:'));
    console.log(chalk.white('  node fix-file.js <文件路径> [修复类型]'));
    console.log(chalk.white(''));
    console.log(chalk.white('修复类型:'));
    console.log(chalk.white('  naming    - 修复文件命名（添加Alyr-前缀）'));
    console.log(chalk.white('  copyright - 添加版权声明'));
    console.log(chalk.white('  both      - 同时修复命名和版权（默认）'));
    console.log(chalk.white(''));
    console.log(chalk.white('示例:'));
    console.log(chalk.yellow('  node fix-file.js ../server/test.service.ts naming'));
    console.log(chalk.yellow('  node fix-file.js ../server/test.service.ts copyright'));
    return;
  }

  const filePath = path.resolve(args[0]);
  const fixType = args[1] || 'both';
  
  const helper = new AutoFixHelper();
  
  console.log(chalk.cyan(`\n🔧 开始修复文件: ${path.basename(filePath)}`));
  
  if (fixType === 'naming' || fixType === 'both') {
    await helper.interactiveFix(filePath, 'naming');
  }
  
  if (fixType === 'copyright' || fixType === 'both') {
    await helper.interactiveFix(filePath, 'copyright');
  }
  
  console.log(chalk.green(`\n✅ 修复完成！`));
}

main().catch(error => {
  console.error(chalk.red(`❌ 修复失败: ${error.message}`));
  process.exit(1);
});